import axios from "axios";
import { message } from "ant-design-vue";

axios.defaults.baseURL = "/api";

axios.interceptors.request.use(
  (config) => {
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);

// add response interceptors
axios.interceptors.response.use(
  (response) => {
    const res = response.data;
    if (res.code !== 0) {
      message.error(res.msg || "数据错误", 0.5);
      return Promise.reject(new Error(res.msg || "加载出错"));
    }
    return res;
  },
  (error) => {
    message.error(error.msg || "请求错误", 0.5);
    return Promise.reject(error);
  }
);
